package com.bokee.archerwq.lab.mina.codec;

import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import com.bokee.archerwq.lab.mina.message.Request;

public class RequestEncoder extends ProtocolEncoderAdapter {

	@Override
	public void encode(IoSession session, Object message,
			ProtocolEncoderOutput out) throws Exception {
		Request request = (Request) message;
		ByteBuffer buffer = ByteBuffer.allocate(10, false);
		buffer.put(request.getId().getBytes());
		buffer.flip();
		out.write(buffer);
		out.flush();
	}

}
